<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Api_Model_Location
{
	private $location_id;
	private $city_id;
	private $user_id;
	private $location_name;
	private $description;
	private $longitude;
	private $latitude;
	private $rating;
	private $rateTimes;
	private $created_time;
	private $updated_time;

	public function __construct($location_row = null) {
		if(!is_null($location_row) && $location_row instanceof Zend_Db_Table_Row) {
			$this->location_id = $location_row->location_id;
			$this->city_id = $location_row->city_id;
			$this->user_id = $location_row->user_id;
			$this->location_name = $location_row->location_name;
			$this->description = $location_row->description;
			$this->longitude = $location_row->longitude;
			$this->latitude = $location_row->latitude;
			$this->rating = $location_row->rating;
			$this->rateTimes = $location_row->rateTimes;
			$this->created_time = $location_row->created_time;
			$this->updated_time = $location_row->updated_time;
		}
	}

	public function __set($name, $value) {
		switch($name) {
			case 'location_id':
				if(!is_null($this->location_id)) {
					throw new Exception('Cannot update location\'s id');
				}
				break;
			case 'city_id':
				if(!is_null($this->city_id)) {
					throw new Exception('Cannot update city\'s id');
				}
				break;
			case 'user_id':
				if(!is_null($this->user_id)) {
					throw new Exception('Cannot update user\'s id');
				}
				break;
			case 'location_name':
				if(!is_null($this->location_name)) {
					throw new Exception('Cannot update location name');
				}
				break;
			case 'description':
				if(!is_null($this->description)) {
					throw new Exception('Cannot update description');
				}
				break;
			case 'longitude':
				if(!is_null($this->longitude)) {
					throw new Exception('Cannot update longitude');
				}
				break;
			case 'latitude':
				if(!is_null($this->latitude)) {
					throw new Exception('Cannot update latitude');
				}
				break;
			case 'rating':
				if(!is_null($this->latitude)) {
					throw new Exception('Cannot update rating');
				}
				break;
			case 'rateTimes':
				if(!is_null($this->latitude)) {
					throw new Exception('Cannot update rateTimes');
				}
				break;
			case 'created_time':
				if(!is_null($this->created_time)) {
					throw new Exception('Cannot update created_time');
				}
				break;
			case 'updated_time':
				if(!is_null($this->updated_time)) {
					throw new Exception('Cannot update updated_time');
				}
				break;
		}
		$this->$name = $value;
	}

	public function __get($name) {
		return $this->$name;
	}
}
